using IcsSEMCtrl.Global;
using IcsSEMCtrl.Global.Exception;
using IcsSEMCtrl.Service.Logger;
using System;
using System.Collections.Generic;
namespace IcsSEMCtrl.Util.UDProperty
{
	public abstract class AbstractUserDefindManager
	{
		private const string CLASS = "AbstractUserDefindManager";
		private Dictionary<string, UserDefinedProperty> userDefinedProperties = new Dictionary<string, UserDefinedProperty>();
		private static object udplist_monitor = new object();
		public Dictionary<string, UserDefinedProperty> UDP
		{
			get
			{
				return this.userDefinedProperties;
			}
			set
			{
				this.userDefinedProperties = value;
			}
		}
		public abstract string GetUserDefinedEntityClassName();
		public abstract string GetUserDefineEntityId();
		public void AddUserDefinedProperty(string name, string value, string requestor)
		{
			Console.WriteLine("AbstractUserDefindManager.AddUserDefinedProperty:CALLED");
			try
			{
				lock (AbstractUserDefindManager.udplist_monitor)
				{
					if (this.userDefinedProperties.ContainsKey(name))
					{
						throw new ECPException(ECPExceptionType.DUPLICATE, name, "User Defined Property(" + name + ") already exists ");
					}
					UserDefinedProperty value2 = UserDefinedProperty.NewUserDefinedProperty(this.GetUserDefinedEntityClassName(), this.GetUserDefineEntityId(), name, value);
					this.userDefinedProperties.Add(name, value2);
				}
			}
			catch (ECPException ex)
			{
				throw ex;
			}
			catch (Exception ex2)
			{
			}
		}
		public string GetUserDefinedPropertyValue(string name)
		{
			Console.WriteLine("AbstractUserDefindManager.GetUserDefinedPropertyValue:CALLED");
			string result;
			try
			{
				if (this.userDefinedProperties.ContainsKey(name))
				{
					result = this.userDefinedProperties[name].Value;
					return result;
				}
				throw new ECPException(ECPExceptionType.NOT_FOUND, name, "User Defined Property (" + name + ") not found");
			}
			catch (ECPException ex)
			{
				throw ex;
			}
			catch (Exception ex2)
			{
			}
			result = null;
			return result;
		}
		public void SetUserDefinedPropertyValue(string name, string value, string requestor)
		{
			Console.WriteLine("AbstractUserDefindManager.SetUserDefinedPropertyValue:CALLED");
			try
			{
				lock (AbstractUserDefindManager.udplist_monitor)
				{
					if (this.userDefinedProperties.ContainsKey(name))
					{
						this.userDefinedProperties[name].Value = value;
					}
					else
					{
						this.AddUserDefinedProperty(name, value, requestor);
					}
				}
			}
			catch (ECPException ex)
			{
				throw ex;
			}
			catch (Exception ex2)
			{
			}
		}
		public void DeleteUserDefinedProperty(string name, string requestor)
		{
			Console.WriteLine("AbstractUserDefindManager.DeleteUserDefinedProperty:CALLED");
			try
			{
				lock (AbstractUserDefindManager.udplist_monitor)
				{
					if (!this.userDefinedProperties.ContainsKey(name))
					{
						throw new ECPException(ECPExceptionType.NOT_FOUND, name, "User Defined Property (" + name + ") not found");
					}
					this.userDefinedProperties[name].Delete();
					this.userDefinedProperties.Remove(name);
				}
			}
			catch (ECPException ex)
			{
				throw ex;
			}
			catch (Exception ex2)
			{
			}
		}
		public List<UserDefinedPropertyInfo> GetUserDefinedProperties()
		{
			Console.WriteLine("AbstractUserDefindManager.GetUserDefinedProperties:CALLED");
			List<UserDefinedPropertyInfo> list = new List<UserDefinedPropertyInfo>();
			List<UserDefinedPropertyInfo> result;
			try
			{
				lock (AbstractUserDefindManager.udplist_monitor)
				{
					foreach (UserDefinedProperty current in this.userDefinedProperties.Values)
					{
						list.Add(new UserDefinedPropertyInfo(current.Name, current.Value));
					}
					result = list;
					return result;
				}
			}
			catch (Exception ex)
			{
			}
			result = null;
			return result;
		}
		public void DeleteAllUserDefinedProperties(string requestor)
		{
			Console.WriteLine("AbstractUserDefindManager.DeleteAllUserDefinedProperties:CALLED");
			try
			{
				lock (AbstractUserDefindManager.udplist_monitor)
				{
					UserDefinedProperty.DeleteAllForEntity(this.GetUserDefinedEntityClassName(), this.GetUserDefineEntityId());
					this.userDefinedProperties.Clear();
				}
			}
			catch (ECPException ex)
			{
				throw ex;
			}
			catch (Exception ex2)
			{
			}
		}
		public void LoadUserDefinedProperties()
		{
			try
			{
				this.userDefinedProperties = UserDefinedProperty.GetUserDefinedPropertiesForEntity(this.GetUserDefinedEntityClassName(), this.GetUserDefineEntityId());
			}
			catch (ECPException ex)
			{
				throw ex;
			}
			catch (Exception ex2)
			{
				throw ex2;
			}
		}
	}
}
